package visual;

import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;

import persistencia.ConexaoMantis;

/**
 * 
 * 
 * @author Everton Moura
 * @author Velsoni Selle
 */
public class DadosConexao_HELP_PM extends JInternalFrame {
	private JTextField textIp;
	private JTextField textPorta;
	private JTextField textDatabase;
	private JTextField textUsuario;
	private JTextField textSenha;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					DadosConexao_HELP_PM frame = new DadosConexao_HELP_PM();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public DadosConexao_HELP_PM() {
		setTitle("Configura\u00E7\u00E3o");
		setBounds(100, 100, 436, 350);

		JPanel panel = new JPanel();

		JPanel panel_1 = new JPanel();

		JButton btnTestar = new JButton("Testar");
		btnTestar.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {

				/**
				 * Pegar os Dados para poder criar a conexao com a base de dados
				 * do mantis
				 */
				String ipConexao = textIp.getText();
				String portaConexao = textPorta.getText();
				String banco = textDatabase.getText();
				String usuario = textUsuario.getText();
				String senha = textSenha.getText();
				ConexaoMantis connection = ConexaoMantis.getInstance();
				/**
				 * Usar uma conexao fake de teste para validar os dados, se
				 * passar, criar a conexao original
				 */

				connection.setIP(ipConexao);
				connection.setPORT(portaConexao);
				connection.setDATABASE(banco);
				connection.setUSER(usuario);

				if (connection.conexaoOk()) {
					JOptionPane.showMessageDialog(null, "Foi");
				}

			}
		});
		btnTestar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
			}
		});

		JButton btnConfirmarDados = new JButton("Confirmar Dados");
		btnConfirmarDados.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				System.exit(DISPOSE_ON_CLOSE);
			}
		});
		GroupLayout groupLayout = new GroupLayout(getContentPane());
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(34)
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 346, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(40, Short.MAX_VALUE))
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(btnTestar)
					.addPreferredGap(ComponentPlacement.RELATED, 194, Short.MAX_VALUE)
					.addComponent(btnConfirmarDados)
					.addGap(44))
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel_1, GroupLayout.PREFERRED_SIZE, 404, GroupLayout.PREFERRED_SIZE)
					.addContainerGap(117, Short.MAX_VALUE))
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addContainerGap()
					.addComponent(panel, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(panel_1, GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)
					.addGap(42)
					.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
						.addComponent(btnTestar)
						.addComponent(btnConfirmarDados))
					.addContainerGap())
		);

		JLabel labelIp = new JLabel("Ip:");

		JLabel lblPorta = new JLabel("Porta:");

		JLabel lblDatabaseName = new JLabel("Database Name:");

		JLabel lblUsuario = new JLabel("Usuario:");

		JLabel lblSenha = new JLabel("Senha:");

		textIp = new JTextField();
		textIp.setColumns(10);

		textPorta = new JTextField();
		textPorta.setColumns(10);

		textDatabase = new JTextField();
		textDatabase.setColumns(10);

		textUsuario = new JTextField();
		textUsuario.setColumns(10);

		textSenha = new JTextField();
		textSenha.setColumns(10);
		GroupLayout gl_panel_1 = new GroupLayout(panel_1);
		gl_panel_1.setHorizontalGroup(gl_panel_1.createParallelGroup(
				Alignment.LEADING).addGroup(
				gl_panel_1
						.createSequentialGroup()
						.addContainerGap()
						.addGroup(
								gl_panel_1
										.createParallelGroup(Alignment.LEADING)
										.addComponent(lblSenha)
										.addComponent(lblUsuario)
										.addComponent(lblDatabaseName)
										.addComponent(labelIp)
										.addComponent(lblPorta))
						.addGap(25)
						.addGroup(
								gl_panel_1
										.createParallelGroup(Alignment.LEADING,
												false)
										.addComponent(textPorta,
												GroupLayout.PREFERRED_SIZE, 44,
												GroupLayout.PREFERRED_SIZE)
										.addComponent(textUsuario)
										.addComponent(textIp,
												GroupLayout.DEFAULT_SIZE, 153,
												Short.MAX_VALUE)
										.addComponent(textDatabase)
										.addComponent(textSenha))
						.addContainerGap(136, Short.MAX_VALUE)));
		gl_panel_1
				.setVerticalGroup(gl_panel_1
						.createParallelGroup(Alignment.LEADING)
						.addGroup(
								gl_panel_1
										.createSequentialGroup()
										.addGap(20)
										.addGroup(
												gl_panel_1
														.createParallelGroup(
																Alignment.TRAILING)
														.addComponent(
																textIp,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(labelIp))
										.addGap(12)
										.addGroup(
												gl_panel_1
														.createParallelGroup(
																Alignment.BASELINE)
														.addComponent(lblPorta)
														.addComponent(
																textPorta,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE))
										.addGap(18)
										.addGroup(
												gl_panel_1
														.createParallelGroup(
																Alignment.BASELINE)
														.addComponent(
																textDatabase,
																GroupLayout.PREFERRED_SIZE,
																GroupLayout.DEFAULT_SIZE,
																GroupLayout.PREFERRED_SIZE)
														.addComponent(
																lblDatabaseName))
										.addPreferredGap(
												ComponentPlacement.UNRELATED)
										.addGroup(
												gl_panel_1
														.createParallelGroup(
																Alignment.TRAILING)
														.addGroup(
																gl_panel_1
																		.createSequentialGroup()
																		.addComponent(
																				lblUsuario)
																		.addGap(18)
																		.addComponent(
																				lblSenha))
														.addGroup(
																gl_panel_1
																		.createSequentialGroup()
																		.addComponent(
																				textUsuario,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				ComponentPlacement.UNRELATED)
																		.addComponent(
																				textSenha,
																				GroupLayout.PREFERRED_SIZE,
																				GroupLayout.DEFAULT_SIZE,
																				GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				ComponentPlacement.RELATED)))
										.addContainerGap(17, Short.MAX_VALUE)));
		panel_1.setLayout(gl_panel_1);

		JLabel lblInsiraOsDados = new JLabel(
				"Insira os dados referente da sua base de dados Mantis");
		panel.add(lblInsiraOsDados);
		getContentPane().setLayout(groupLayout);

	}
}
